﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CPPEI.Coolzon.ViewState
{
    /// <summary>
    /// 场景路径
    /// </summary>
    public class ScenePath
    {
        public string OpenMode { get; set; }
        public string SceneName { get; set; }
        public string Arguments { get; set; }
        public ScenePath Parent { get; set; }

        public ScenePath(string openMode, string sceneName)
        {
            this.OpenMode = openMode;
            this.SceneName = sceneName;
        }

        public ScenePath(string openMode, string sceneName, string arguments)
        {
            this.OpenMode = openMode;
            this.SceneName = sceneName;
            this.Arguments = arguments;
        }

        public ScenePath(string openMode, string sceneName, ScenePath parent)
        {
            this.OpenMode = openMode;
            this.SceneName = sceneName;
            this.Parent = parent;
        }

        public ScenePath(string openMode, string sceneName, string arguments, ScenePath parent)
        {
            this.OpenMode = openMode;
            this.SceneName = sceneName;
            this.Arguments = arguments;
            this.Parent = parent;
        }

        public ScenePath GetRoot()
        {
            ScenePath root = null;
            ScenePath parent = this;
            while (parent != null)
            {
                root = parent;
                parent = parent.Parent;
            }
            return root;
        }

        /// <summary>
        /// 获取parent的下一个子节点
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public ScenePath GetChild(ScenePath parent)
        {
            ScenePath child = null;
            ScenePath latest = null;
            ScenePath parentTmp = this;
            while (parentTmp != null)
            {
                if (parentTmp == parent)
                {
                    child = latest;
                    parentTmp = null;
                }
                else
                {
                    latest = parentTmp;
                    parentTmp = parentTmp.Parent;
                }
            }
            return child;
        }
    }
}
